int addDigits(int num)
{
    while (num / 10)
    {
        int x = num;
        int cal = 0;
        while (x)
        {
            cal += x % 10;
            x /= 10;
        }
        num = cal;
    }
    return num;
}